package com.suning.sawp.web.controller;

import java.security.Principal;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.suning.sawp.constants.RegAndBindErrCodeConstants;
import com.suning.sawp.dto.clerk.ClerkBindEbuyRtn;
import com.suning.sawp.dto.clerk.MyInvitationCodeNew;
import com.suning.sawp.dto.clerk.MyInvitationCodeRtn;
import com.suning.sawp.dto.clerk.RedPonitTips;
import com.suning.sawp.dto.common.ReturnMsg;
import com.suning.sawp.intf.clerk.ClerkService;
import com.suning.sawp.web.exception.MyGsonView;
import com.suning.vgs.follow.remote.store.StoreManEbuyAccount;

/**
 * 店员相关操作
 * 
 * @author 14062606
 * @see [相关类/方法]
 * @since 
 */
@Controller
@RequestMapping("/user")
public class ClerkController extends DjBaseController {
	/**
     * 日志
     */
    private static final Logger LOGGER = LoggerFactory.getLogger(ClerkController.class);
	
    @Resource
    ClerkService clerkService;

	/**
	 * 获取店员邀请码
	 * @param principal
	 * @return
	 */
	@RequestMapping("/getMyInvitationCode.do")
	public MyGsonView getMyInvitationCode(Principal principal){
		LOGGER.debug("开始查询店员邀请码,staffId:{}", principal.getName());
		ReturnMsg<MyInvitationCodeRtn> ret = new ReturnMsg<MyInvitationCodeRtn>();
		String staffId = principal.getName();
		try {
			ret = clerkService.getMyInvitationCode(staffId);
		} catch (Exception e){
			ret.setRetFlag(ReturnMsg.FAIL);
	    	ret.setErrorCode(RegAndBindErrCodeConstants.COMMON_ERR_E999);
	    	ret.setErrorMessage(RegAndBindErrCodeConstants.COMMON_ERR_MAP
	    			.get(RegAndBindErrCodeConstants.COMMON_ERR_E999));
	    	LOGGER.error("查询店员邀请码发生异常，staffId:{}, error:{}", principal.getName(), e);
		}
		return setGsonView(ret);
	}
	
	@RequestMapping("/getMyInvitationCodeNew.do")
	public MyGsonView getMyInvitationCodeNew(Principal principal){
        LOGGER.debug("getMyInvitationCodeNew.do,staffId:{}", principal.getName());
        ReturnMsg<MyInvitationCodeNew> ret = new ReturnMsg<MyInvitationCodeNew>();
        String staffId = principal.getName();
        try {
            ret = clerkService.getMyInvitationCodeNew(staffId);
        } catch (Exception e){
            ret.setRetFlag(ReturnMsg.FAIL);
            ret.setErrorCode(RegAndBindErrCodeConstants.COMMON_ERR_E999);
            ret.setErrorMessage(RegAndBindErrCodeConstants.COMMON_ERR_MAP
                    .get(RegAndBindErrCodeConstants.COMMON_ERR_E999));
            LOGGER.error("getMyInvitationCodeNew.do，staffId:{}", principal.getName(), e);
        }
        return setGsonView(ret);
    }
	
	/**
	 * 
	 * 功能描述: 店员绑定归属易购账号<br>
	 * 〈功能详细描述〉
	 *
	 * @return
	 * @see [相关类/方法](可选)
	 * @since [产品/模块版本](可选)
	 */
	@RequestMapping("/clerkBindEbuyNo.do")
	public MyGsonView clerkBindEbuyNo(String ebuyNum, Principal principal) {
	    ReturnMsg<String> retMsg = clerkService.clerkBindEbuyNo(ebuyNum, principal.getName());
	    return setGsonView(retMsg);
	}
	
	/**
     * 
     * 功能描述: 店员绑定归属易购账号<br>
     * 〈功能详细描述〉
     *
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/clerkBindEbuyNoNew.do")
    public MyGsonView clerkBindEbuyNoNew(String ebuyNum, Principal principal) {
        ReturnMsg<ClerkBindEbuyRtn> retMsg = clerkService.clerkBindEbuyNoNew(ebuyNum, principal.getName());
        return setGsonView(retMsg);
    }
	
	/**
	 * 
	 * 功能描述: 查询店员绑定易购账号接口<br>
	 * 〈功能详细描述〉
	 *
	 * @param principal
	 * @return
	 * @see [相关类/方法](可选)
	 * @since [产品/模块版本](可选)
	 */
	@RequestMapping("/queryBindEbuyNo.do")
	public MyGsonView queryBindEbuyNo(Principal principal) {
	    ReturnMsg<StoreManEbuyAccount> retMsg = clerkService.queryBindEbuyNo(principal.getName());
        return setGsonView(retMsg);
	}
	
	/**
	 * 
	 * 功能描述: 查询我页面-小红点提示<br>
	 * 〈功能详细描述〉
	 *
	 * @param principal
	 * @return
	 * @see [相关类/方法](可选)
	 * @since [产品/模块版本](可选)
	 */
	@RequestMapping("/redPointTips.do")
	public MyGsonView redPointTips(Principal principal) {
	    ReturnMsg<RedPonitTips> retMsg = clerkService.queryMyRedPointTips(principal.getName());
	    return setGsonView(retMsg);
	}
}
